package com.ruoyi.common.core.domain.model;

import com.eic.framework.security.LoginJwtHandler;

public abstract class JwtLoginUser implements LoginUser{
    private LoginJwtHandler jwt=null;

    public void setJwt(LoginJwtHandler jwt){
        this.jwt=jwt;
    }

    public void setUserId(String userId){
        initJwt();
        jwt.setUserId(userId);
    }

    @Override
    public String getUserId() {
        return jwt.getUserId();
    }

    private static String USERNAMEFIELDNAME="un";
    @Override
    public String getUserName() {
        return jwt.getValue(USERNAMEFIELDNAME);
    }

    public void setUserName(String userName){
        initJwt();
        jwt.setValue(USERNAMEFIELDNAME,userName);
    }

    public void setTerm(String term){
        initJwt();
        jwt.setTerm(term);
    }

    @Override
    public String getTerm(){
        return jwt.getTerm();
    }

    public void setPlatform(String platform){
        initJwt();
        jwt.setPlatform(platform);
    }

    @Override
    public String getPlatform(){
        return jwt.getPlatform();
    }

    private static String DEPTFIELDNAME="dept";
    public void setDeptId(String deptId){
        initJwt();
        jwt.setValue(DEPTFIELDNAME,deptId);
    }
    @Override
    public String getDeptId(){
        return jwt.getValue(DEPTFIELDNAME);
    }
    private static String ROLEFIELDNAME="role";
    public void setRoles(String roles){
        initJwt();
        jwt.setValue(ROLEFIELDNAME,roles);
    }
    @Override
    public String getRoles(){
        return jwt.getValue(ROLEFIELDNAME);
    }

    @Override
    public String getToken(){
        return jwt.getToken();
    }

    @Override
    public final String getSessionId(){
        return jwt.getCacheId();
    }

    private void initJwt(){
        if(jwt==null){
            jwt=LoginJwtHandler.newInstanse();
            jwt.setLoginTime(System.currentTimeMillis());
        }
    }
}
